Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiple providers/llms #45

Merged
merged 6 commits into from
Feb 5, 2025
Merged

Conversation

mbertrand
Copy link
Member

@mbertrand mbertrand commented Jan 31, 2025

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/6622

Description (What does it do?)

  • Adds the langchain-community library and uses the ChatLiteLLM class for all LLM models.
  • Updates the LiteLLMProxy default kwargs to work with this class.
  • Adds support for one bedrock anthropic model in the LiteLLM proxy server configuration.
  • Sets different configurable default models for each bot.

How can this be tested?

  • You'll need this env value set (same as heroku mit-learn RC) in backend.local.env : OPENAI_API_KEY
  • Start the containers and go to http://ai.open.odl.local:8003. Ask some questions, it should work. Look at the logs, you should find this:
    web-1         | LiteLLM completion() model= gpt-4o; provider = openai
  • Add AI_DEFAULT_RECOMMENDATION_MODEL=openai/o3-mini to your backend.local.env file and restart containers.
  • Try the chat UI again. It should still work and you should see this in the logs:
    web-1         | LiteLLM completion() model= o3-mini; provider = openai
  • Add the following env settings to backend.local.env:
    AI_PROXY_URL=http://litellm:4000
    AI_PROXY_AUTH_TOKEN=sk-secret
    LITELLM_MASTER_KEY=sk-secret
    LITELLM_PROXY_API_KEY
    AI_PROXY_CLASS=LiteLLMProxy
    
  • Restart containers and interact with the chatbot again. It should still work and logs should indicate that the requests are going to the LiteLLM proxy service:
      litellm-1     | LiteLLM completion() model= o3-mini; provider = openai
    

Comment on lines +50 to +51
# AWS_ACCESS_KEY_ID=
# AWS_SECRET_ACCESS_KEY=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for AWS Bedrock models

"ignore",
module=".*(pydantic).*",
category=UserWarning,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pydantic warnings coming from ChatLiteLLM class

**(self.proxy.get_api_kwargs() if self.proxy else {}),
**(self.proxy.get_additional_kwargs(self) if self.proxy else {}),
**kwargs,
)
if self.temperature:
if self.temperature and self.model not in settings.AI_UNSUPPORTED_TEMP_MODELS:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new o3-mini model does not support the temperature parameter and will raise an exception if it is passed along

Comment on lines -160 to +143
agent_graph.add_conditional_edges(
agent_node,
continue_on_tool_call,
{
# If tool requested then we call the tool node.
CONTINUE: tools_node,
# Otherwise finish.
END: END,
},
)
agent_graph.add_conditional_edges(agent_node, tools_condition)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example was probably more verbose than it needed to be, the built in tools_condition function should suffice for most use cases.

@@ -447,7 +421,7 @@ def __init__( # noqa: PLR0913
super().__init__(
user_id,
name=name,
model=model or settings.AI_MODEL,
model=model or settings.AI_DEFAULT_SYLLABUS_MODEL,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After AWS Bedrock access is set up, the default syllabus model should be changed to bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0

@abeglova abeglova self-assigned this Feb 4, 2025
Copy link

@abeglova abeglova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mbertrand mbertrand merged commit 9364145 into main Feb 5, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants